﻿using System;

namespace Palindromes
{
  /// <summary>
  /// Gives set of methods to print messages on console.
  /// </summary>
  public class PalindromeConsolePrinter
  {
    #region private vars
    /// <summary>
    /// Text color for messges, points to right cursot shifting.
    /// </summary>
    private readonly ConsoleColor RightCursorShifting = ConsoleColor.Blue;

    /// <summary>
    /// Text color for messges, points to left cursot shifting.
    /// </summary>
    private readonly ConsoleColor LeftCursorShifting = ConsoleColor.Green;

    /// <summary>
    /// Text color for messges about initial positions of cursors.
    /// </summary>
    private readonly ConsoleColor InitialPosition = ConsoleColor.DarkGray;

    /// <summary>
    /// Text color for messges indicating exit.
    /// </summary>
    private readonly ConsoleColor ExitingForegroundColor = ConsoleColor.DarkRed;

    /// <summary>
    /// Text color for messges, points symbol testing.
    /// </summary>
    private readonly ConsoleColor SymbolTestingForegroundColor = ConsoleColor.Red;
    #endregion

    #region public methods
    /// <summary>
    /// Writes message about symbol comparing.
    /// </summary>
    /// <param name="input">input string</param>
    /// <param name="leftIndex">left symbol index</param>
    /// <param name="rightIndex">right symbol index</param>
    public void WriteComparingSymbols(string input, 
      int leftIndex, int rightIndex)
    {
      Console.ForegroundColor = SymbolTestingForegroundColor;
      Console.WriteLine(ConsoleMessages.SymbolComparsion,
                        leftIndex, rightIndex,
                        input[leftIndex], input[rightIndex]);
      Console.ResetColor();
    }

    /// <summary>
    /// Writes end (by left cursor position matches right cursor position).
    /// </summary>
    public void WriteEndWhileShiftingLeftCursor()
    {
      Console.ForegroundColor = ExitingForegroundColor;
      Console.WriteLine(ConsoleMessages.EndWithLeftIndexMatchesRight);
      Console.ResetColor();
    }

    /// <summary>
    /// Writes end (by right cursor position matches left cursor position).
    /// </summary>
    public void WriteEndWhileShiftingRightCursor()
    {
      Console.ForegroundColor = ExitingForegroundColor;
      Console.WriteLine(ConsoleMessages.EndWithRightIndexMatchesLeft);
      Console.ResetColor();
    }

    /// <summary>
    /// Writes position of right cursor.
    /// </summary>
    /// <param name="rightIndex">index of right cursor</param>
    public void WriteCurrentRightCursorPosition(int rightIndex)
    {
      Console.ForegroundColor = RightCursorShifting;
      Console.WriteLine(ConsoleMessages.RightIndexCurrentPosition, rightIndex);
      Console.ResetColor();
    }

    /// <summary>
    /// Writes position of left cursor.
    /// </summary>
    /// <param name="leftIndex">index of left cursor</param>
    public void WriteCurrentLeftCursorPosition(int leftIndex)
    {
      Console.ForegroundColor = LeftCursorShifting;
      Console.WriteLine(ConsoleMessages.LeftIndexCurrentPosition, leftIndex);
      Console.ResetColor();
    }

    /// <summary>
    /// Writes initial positions of cursor.
    /// </summary>
    /// <param name="leftIndex">index of left cursor</param>
    /// <param name="rightIndex">index of right cursor</param>
    public void WriteInitialPositions(int leftIndex, int rightIndex)
    {
      Console.ForegroundColor = InitialPosition;
      Console.WriteLine(ConsoleMessages.IntialIndexes, leftIndex, rightIndex);
      Console.ResetColor();
    }

    /// <summary>
    /// Writes message abour shifring left cursor to right.
    /// </summary>
    /// <param name="currentIndex">index of cursor </param>
    public void WriteShiftingStepFromLeft(int currentIndex)
    {
      Console.ForegroundColor = LeftCursorShifting;
      Console.WriteLine(ConsoleMessages.LeftIndexShifting, currentIndex);
      Console.ResetColor();
    }

    /// <summary>
    /// Writes message abour shifring right cursor to left.
    /// </summary>
    /// <param name="currentIndex">index of cursor </param>
    public void WriteShiftingStepFromRight(int currentIndex)
    {
      Console.ForegroundColor = RightCursorShifting;
      Console.WriteLine(ConsoleMessages.RightIndexShifting, currentIndex);
      Console.ResetColor();
    }

    /// <summary>
    /// Writes message about delimiter symbol skipped
    /// </summary>
    /// <param name="input">input string</param>
    /// <param name="index">index of delimiter to be skipped</param>
    public void WriteSkippingDelimiter(string input, int index)
    {
      Console.ForegroundColor = SymbolTestingForegroundColor;
      Console.WriteLine(ConsoleMessages.DelimiterSkipping,
                        index, input[index]);
      Console.ResetColor();
    }

    /// <summary>
    /// Writes result of testing to be palindrome.
    /// </summary>
    /// <param name="isPalindrom">result of testing</param>
    public void WriteResult(bool isPalindrom)
    {
      Console.WriteLine();
      Console.ForegroundColor = ExitingForegroundColor;
      Console.WriteLine(isPalindrom
                          ? ConsoleMessages.AnswerOk
                          : ConsoleMessages.AnswerFail);
      Console.ResetColor();
    }

    /// <summary>
    /// Write prompt for user
    /// </summary>
    public void WritePrompt()
    {
      Console.WriteLine();
      Console.WriteLine(ConsoleMessages.Prompt);
    }

    /// <summary>
    /// Writes welcome message
    /// </summary>
    public void WriteWelcome()
    {
      Console.WriteLine(ConsoleMessages.Welcome, Environment.NewLine);
    }

    /// <summary>
    /// Writes exit message
    /// </summary>
    public void WriteExit()
    {
      Console.WriteLine(ConsoleMessages.Exit);
    }
    #endregion
  }

}
